﻿using SmartHotel.DAL;
using SmartHotel.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartHotel.BLL
{
    public class ProductBLL
    {
        public ProductBLL(ProductDAL productDAL)
        {
            ProductDAL = productDAL;
        }

        public ProductDAL ProductDAL { get; }

        /// <summary>
        /// 添加商品的数据访问层方法  
        /// </summary>
        /// <param name="product">商品对象</param>
        /// <returns></returns>
        public int AddProduct(Product product)
        {
           return ProductDAL.AddProduct(product);
        }
        /// <summary>
        /// 根据id查找商品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Product GetProductById(int id)
        {

            return ProductDAL.GetProductById(id);
        }

        public int UpdateProduct(Product product)
        {
            return ProductDAL.UpdateProduct(product);
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteProduct(int id)
        {
            return ProductDAL.DeleteProduct(id);
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int LogicDelte(int id)
        {
            return ProductDAL.LogicDelte(id);
        }

        public MyPage<Product> GetProductPages(int index, int size, out int count,
            string? Name, DateTime? beginTime, DateTime? endTime)
        {
           var data = ProductDAL.GetProductPages(index,size,out count,Name, beginTime, endTime);
            MyPage<Product> page = new MyPage<Product>();
            page.Data = data;
            page.Size = size;
            page.Count = count;
            return page;
        }

        /// <summary>
        /// BLL层的分页方法
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="count"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public MyPage<Product> GetProductFenYe(int index, int size, out int count, string? name) {

            var data = ProductDAL.GetProductFenYe(index,size,out count,name);   

            MyPage<Product> page = new MyPage<Product>();
            page.Count = count;
            page.Data = data;
            page.Size = size;   

            return page;
        }

        public int DuiHuan(string userName, int productId)
        {
            return ProductDAL.DuiHuan(userName,productId);
        }
    }
}
